import {
  getDataApi,
  getQuestionsApi,
  deleteMsbdApi
} from '../../api/msbd'

export default {
  namespaced: true,
  state: {
    list: [],
    currentPage: 0,
    // num:0
    // totals: {},
    questions: [],
    total: 0,
    index:0
  },
  mutations: {
    SET_LIST(state, list) {
      // state.list = list
      state.list = state.list.concat(list)
    },
    SET_CURRENT_PAGE(state, page) {
      state.currentPage = page
      // console.log(state.list)
      // console.log(state.list[0])
      for (let i = 0; i < state.list.length; i++) {
        state.num = state.list.length
      }
    },
    // SET_TOTAL (state, totals) {
    //   state.totals = totals
    //   // console.log(state.total)
    // },
    SET_ADD_PAGE(state) {
      state.list = []
    },
    SET_QUESTIONS(state, questions) {
      state.questions = questions
    },
    SET_TOTAL(state, total) {
      state.total = total
    },
    setIndex(state, index) {
      state.index = index
    }
  },
  actions: {
    async getList({
      commit,
      state
    }) {
      let r = await getDataApi({
        currentPage: state.currentPage
      })
      commit('SET_LIST', r.data.data)
      commit('SET_TOTAL', r.data.total)
      // console.log(r.data.total)
      // console.log(rdata.data)
    },
    async getQuestion({
      commit
    }) {
      let r = await getQuestionsApi()
      commit('SET_QUESTIONS', JSON.parse(r.data.data))
      // console.log(r.data)
    },
    async deleteMsbd({
      commit
    }, data) {
      await deleteMsbdApi({
        id: data.id
      })
    }
  },
  getters: {

  }
}